<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>css | 掏钱的机器猫</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/vue-admin-ui/assets/logo.png">
    <meta name="description" content="掏钱的机器猫的个人博客,记录随笔与学习笔记，个人项目等">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/vue-admin-ui/assets/css/0.styles.fb55c927.css" as="style"><link rel="preload" href="/vue-admin-ui/assets/js/app.21d1badc.js" as="script"><link rel="preload" href="/vue-admin-ui/assets/js/3.d02ddc64.js" as="script"><link rel="preload" href="/vue-admin-ui/assets/js/1.38c8ef5a.js" as="script"><link rel="preload" href="/vue-admin-ui/assets/js/11.284df538.js" as="script"><link rel="prefetch" href="/vue-admin-ui/assets/js/10.d9a14dc0.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/12.530bdb86.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/13.3dde5c1a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/14.e18000c4.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/15.65b98979.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/16.953b2589.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/17.d6be13fa.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/18.a10ec5a3.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/19.f2ef083a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/20.9e024a1a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/21.b818c6cd.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/22.f3716a62.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/23.42bfb2a3.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/24.0382e6dc.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/25.9b1cf793.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/26.626abbca.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/27.d6b1a7e8.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/28.7381bce0.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/29.65b69672.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/30.70062600.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/31.036bec0e.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/32.1ec26c99.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/33.69485516.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/34.30a7370c.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/35.1e72f74a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/36.a6aaafe3.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/4.984f5e20.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/5.2cbf0f84.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/6.eab8daa0.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/7.41bb2a3c.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/8.79ebffb7.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/9.e9ae19e3.js">
    <link rel="stylesheet" href="/vue-admin-ui/assets/css/0.styles.fb55c927.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-2d5f533b><div data-v-2d5f533b><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-2d5f533b data-v-2d5f533b><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-64685f0e data-v-2d5f533b data-v-2d5f533b><h3 class="title" style="display:none;" data-v-64685f0e data-v-64685f0e>掏钱的机器猫</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-64685f0e data-v-64685f0e><input type="password" value="" data-v-64685f0e> <span data-v-64685f0e>Konck! Knock!</span> <button data-v-64685f0e>OK</button></label> <div class="footer" style="display:none;" data-v-64685f0e data-v-64685f0e><span data-v-64685f0e><i class="iconfont reco-theme" data-v-64685f0e></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-64685f0e>vuePress-theme-reco</a></span> <span data-v-64685f0e><i class="iconfont reco-copyright" data-v-64685f0e></i> <a data-v-64685f0e><span data-v-64685f0e>Ethan</span>
              
            <span data-v-64685f0e>2018 - </span>
            2022
          </a></span></div></div> <div class="hide" data-v-2d5f533b><header class="navbar" data-v-2d5f533b><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue-admin-ui/" class="home-link router-link-active"><img src="/vue-admin-ui/assets/logo.png" alt="掏钱的机器猫" class="logo"> <span class="site-name">掏钱的机器猫</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
        插件文档
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/vue-admin-ui-lib/" class="nav-link"><i class="iconfont undefined"></i>
    vue-admin-ui-lib
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/submit-valid/" class="nav-link"><i class="iconfont undefined"></i>
    submit-valid
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/open-utils/" class="nav-link"><i class="iconfont undefined"></i>
    open-utils
  </a></li></ul></div></div><div class="nav-item"><a href="/vue-admin-ui/handle/handle/method.html" class="nav-link"><i class="iconfont undefined"></i>
    手写代码
  </a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
        个人站点
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/ethan6" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
    Gitee
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://github.com/Ethan66" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
    Github
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <a href="https://github.com/Ethan66/vue-admin-ui" target="_blank" rel="noopener noreferrer" class="repo-link"><i class="iconfont reco-github"></i>
      Github
      <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask" data-v-2d5f533b></div> <aside class="sidebar" data-v-2d5f533b><div class="personal-info-wrapper" data-v-ca798c94 data-v-2d5f533b><img src="/vue-admin-ui/assets/logo.png" alt="author-avatar" class="personal-img" data-v-ca798c94> <h3 class="name" data-v-ca798c94>
    Ethan
  </h3> <div class="num" data-v-ca798c94><div data-v-ca798c94><h3 data-v-ca798c94>24</h3> <h6 data-v-ca798c94>文章</h6></div> <div data-v-ca798c94><h3 data-v-ca798c94>11</h3> <h6 data-v-ca798c94>标签</h6></div></div> <hr data-v-ca798c94></div> <nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
        插件文档
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/vue-admin-ui-lib/" class="nav-link"><i class="iconfont undefined"></i>
    vue-admin-ui-lib
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/submit-valid/" class="nav-link"><i class="iconfont undefined"></i>
    submit-valid
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/open-utils/" class="nav-link"><i class="iconfont undefined"></i>
    open-utils
  </a></li></ul></div></div><div class="nav-item"><a href="/vue-admin-ui/handle/handle/method.html" class="nav-link"><i class="iconfont undefined"></i>
    手写代码
  </a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
        个人站点
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/ethan6" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
    Gitee
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://github.com/Ethan66" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
    Github
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <a href="https://github.com/Ethan66/vue-admin-ui" target="_blank" rel="noopener noreferrer" class="repo-link"><i class="iconfont reco-github"></i>
      Github
      <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span></span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-admin-ui/article/browser/browser.html" class="sidebar-link">浏览器渲染机制</a></li><li><a href="/vue-admin-ui/article/browser/CSRF,XSS.html" class="sidebar-link">js之安全问题：Cookie、CSRF和XSS</a></li><li><a href="/vue-admin-ui/article/browser/css.html" aria-current="page" class="active sidebar-link">css</a></li><li><a href="/vue-admin-ui/article/browser/Dom.html" class="sidebar-link">DOM</a></li><li><a href="/vue-admin-ui/article/browser/html5.html" class="sidebar-link">html5</a></li><li><a href="/vue-admin-ui/article/browser/performanceOptimize.html" class="sidebar-link">js之页面性能优化</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-64685f0e data-v-2d5f533b><h3 class="title" style="display:none;" data-v-64685f0e data-v-64685f0e>css</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-64685f0e data-v-64685f0e><input type="password" value="" data-v-64685f0e> <span data-v-64685f0e>Konck! Knock!</span> <button data-v-64685f0e>OK</button></label> <div class="footer" style="display:none;" data-v-64685f0e data-v-64685f0e><span data-v-64685f0e><i class="iconfont reco-theme" data-v-64685f0e></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-64685f0e>vuePress-theme-reco</a></span> <span data-v-64685f0e><i class="iconfont reco-copyright" data-v-64685f0e></i> <a data-v-64685f0e><span data-v-64685f0e>Ethan</span>
              
            <span data-v-64685f0e>2018 - </span>
            2022
          </a></span></div></div> <div data-v-2d5f533b><main class="page"><div class="page-title" style="display:none;"><h1 class="title">css</h1> <div data-v-3b7f5bdf><i class="iconfont reco-account" data-v-3b7f5bdf><span data-v-3b7f5bdf>Ethan</span></i> <i class="iconfont reco-date" data-v-3b7f5bdf><span data-v-3b7f5bdf>2020-10-23</span></i> <!----> <i class="iconfont reco-tag tags" data-v-3b7f5bdf><span class="tag-item" data-v-3b7f5bdf>css</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><p><img src="https://drscdn.500px.org/photo/304411367/q%3D80_m%3D1500/v2?webp=true&amp;sig=d62f80a72b6bf36e121e520a251a73e854af1d1e5091b7f4bb81fb7104143644" alt=""></p> <h1 id="css"><a href="#css" class="header-anchor">#</a> css</h1> <h2 id="flex布局"><a href="#flex布局" class="header-anchor">#</a> Flex布局</h2> <p>弹性盒子由弹性容器(Flex container)和弹性子元素(Flex item)组成。容器存在两根轴：水平主轴(main axis)和垂直交叉轴(crosss axis)</p> <h3 id="默认情况"><a href="#默认情况" class="header-anchor">#</a> 默认情况</h3> <p><code>flex-direction: row; flex-wrap: nowrap;</code></p> <ol><li>row: 子元素沿水平主轴由左向右排列</li> <li>nowrap: 让子元素排一行，假如宽度不够的时候全部子元素缩小。</li></ol> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div class="flex-container" style="display:flex;background:#ddd;width:100px;height:80px;"><p class="flex-item" style="background:red;">I'm Item1; </p> <p class="flex-item" style="background:orange;">I'm Item2; </p> <p class="flex-item" style="background:pink;">I'm Item3; </p></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>flex-container<span class="token punctuation" data-v-558b0118>&quot;</span></span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> flex<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 80px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>flex-item<span class="token punctuation" data-v-558b0118>&quot;</span></span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> red<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>I'm Item1; <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>flex-item<span class="token punctuation" data-v-558b0118>&quot;</span></span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> orange<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>I'm Item2; <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>flex-item<span class="token punctuation" data-v-558b0118>&quot;</span></span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> pink<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>I'm Item3; <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118><span class="line-number" data-v-558b0118>7</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><h3 id="容器属性"><a href="#容器属性" class="header-anchor">#</a> 容器属性</h3> <p>1、<code>flex-direction</code>: 改变主轴</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>flex-direction: row | row-reverse | column | column-reverse;
// row(默认)沿水平主轴由左向右排列、row-reverse沿水平主轴由右向左排列、column沿垂直主轴右上到下和column-reverse。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>2、<code>flex-wrap</code>: 是否让子元素一行显示</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>flex-wrap: nowrap | wrap | wrap-reverse;
// nowrap(默认)不换行，让项目一行展示；wrap：宽度不够换行展示；wrap-reverse：换行且反向展示。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>3、<code>flex-flow</code>：将flex-direction和flex-wrap一起设置</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>flex-flow: &lt;flex-direction&gt; || &lt;flex-wrap&gt;;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>4、<code>justify-content</code>: 项目在主轴上的对齐方式（看flex-direction的设置）</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>justify-content: flex-start | flex-end | center | space-between | space-around;
// flex-start：在主轴上由左或者上开始排列。flex-end：在主轴上由右或者下开始排列。
// center：在主轴上居中排列。
// space-between：在主轴上左右两端或者上下两端开始排列。
// space-around：每个项目两侧的间隔相等。所以，项目之间的间隔比项目与边框的间隔大一倍。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>5、<code>align-items</code>: 项目在非主轴上的对齐方式</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>align-items: flex-start | flex-end | center | baseline | stretch;
// baseline: 文字在水平一条线上
// stretch: 让项目在非主轴上撑满
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="项目属性"><a href="#项目属性" class="header-anchor">#</a> 项目属性</h3> <p>1、<code>order</code>: 项目在主轴上的排列顺序。数值越小，排列越靠前，默认为0。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>order: &lt;integer&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>2、<code>flex-grow</code>：项目的放大比例，默认为0，即如果存在剩余空间，也不放大。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>flex-grow: &lt;number&gt;;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>3、<code>flex-shrink</code>：项目的缩小比例，默认为1，即如果空间不足，该项目将缩小。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>flex-shrink: &lt;number&gt;;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>4、<code>flex-basis</code>：项目的初始长度。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>flex-basis: &lt;number&gt; || auto || initial;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>5、<code>flex: flex-grow flex-shrink flex-basis</code></p> <h2 id="响应式布局"><a href="#响应式布局" class="header-anchor">#</a> 响应式布局</h2> <h3 id="视口"><a href="#视口" class="header-anchor">#</a> 视口</h3> <blockquote><p>viewport（视口）就是浏览器中呈现网页的区域。移动端与 PC 端视口不同，PC端的视口宽度等于分辨率，而移动端的视口宽度跟分辨率没有关系，iOS, Android 基本都将这个视口分辨率设置为 980px，因为是绝大多数PC网页的版心宽度。不过PC网页放到移动端基本会缩放，缩放后文字会变得非常小。后来手机厂商会设置约束视口，宽度大概在320~480 之间。能够保证我们的文字比如 16px，在自己的这个视口下清晰、大小刚刚合适。</p></blockquote> <div class="language- line-numbers-mode"><pre class="language-text"><code>// 解决方案：
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0&quot; /&gt;
width=device-width   视口为设备宽度（就是人设置的一个宽度）//不设置的话默认为980px
initial-scale=1.0    初始化的视口大小是1.0倍
maximum-scale=1.0    最大的倍数是1.0倍
user-scalable=0      不允许缩放视口
// 这个视口的标签告诉浏览器怎么渲染网页。在这里，标签想表达的意思是：按照设备的宽度（device-width）来渲染网页内容。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="流式布局"><a href="#流式布局" class="header-anchor">#</a> 流式布局</h3> <blockquote><p>百分比布局也叫作流式布局、弹性盒布局。百分比只能设置的属性width、height、padding、margin</p></blockquote> <div class="language- line-numbers-mode"><pre class="language-text"><code>width: 100%: 父元素 width 的100%
height: 100%: 父元素 height 的100%
padding: 100% 100%: 父元素 width 的100%
margin: 100% 100%: 父元素 width 的100%
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="媒体查询"><a href="#媒体查询" class="header-anchor">#</a> 媒体查询</h3> <blockquote><p>在媒体查询外面写一条规则，用规则区分在不同设备下展示的不同效果</p></blockquote> <div class="language- line-numbers-mode"><pre class="language-text"><code>body {
    background-color: grey;
 }
@media screen and (min-width:1200px){
    body{
        background-color: pink;
	}
}
 @media screen and (min-width:700px) and (max-width:1200px){
    body{
	background-color: blue;
	}
}
@media screen and (max-width:700px){
    body{
	background-color: orange;
        }
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h3 id="rem响应式布局"><a href="#rem响应式布局" class="header-anchor">#</a> rem响应式布局</h3> <blockquote><ol><li>实现原理：rem是根据html的font-size来决定大小的，所以我们用window.resize监听页面宽度来控制html的font-size，从而做到响应式。</li> <li>比如我们暂定750px宽度的时候HTML的font-size: 100px，在开发的时候，设计师给的尺寸是375px宽度，我们就给设计师的宽度px除以50，转为rem。在代码里监听页面宽度设置html的font-size。</li> <li>高度和某些小图标设定固定值。</li></ol></blockquote> <h2 id="bfc"><a href="#bfc" class="header-anchor">#</a> BFC</h2> <h3 id="什么是bfc"><a href="#什么是bfc" class="header-anchor">#</a> 什么是BFC</h3> <blockquote><ol><li>BFC: 块级格式化上下文 (Block Fromatting Context)。他是一个容器，用于管理块级元素，在这个容器中的元素不会影响到其它环境中的布局。</li> <li>如何创建BFC：flex元素，浮动元素和绝对定位元素，overflow值不为“visiable”的块级盒子，设置了相对应属性（例如 inline-block、table-cell、table-caption、inline-flex）</li></ol></blockquote> <h3 id="bfc特性"><a href="#bfc特性" class="header-anchor">#</a> BFC特性</h3> <p>1、相邻或嵌套的两个元素（中间没有阻挡：比如没有边框，没有padding）会发生重叠。</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="background:#ddd;overflow:hidden;width:200px;"><p style="margin-bottom:20px;background:orange;">我是marin-bottom: 20px;</p> <p style="margin-top:20px;background:pink;">我是margin-top: 20px;</p></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>overflow</span><span class="token punctuation" data-v-558b0118>:</span> hidden<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 200px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>margin-bottom</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span>orange<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是marin-bottom: 20px;<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>margin-top</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span>pink<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是margin-top: 20px;<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><p>解决办法：BFC会阻止垂直外边距折叠</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="background:#ddd;overflow:hidden;width:200px;"><p style="margin-bottom:20px;background:orange;">我是marin-bottom: 20px;</p> <div style="overflow:hidden;"><p style="margin-top:20px;background:pink;">我是margin-top: 20px;</p></div></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>overflow</span><span class="token punctuation" data-v-558b0118>:</span> hidden<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 200px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>margin-bottom</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span>orange<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是marin-bottom: 20px;<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>overflow</span><span class="token punctuation" data-v-558b0118>:</span> hidden<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
      <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>margin-top</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span>pink<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是margin-top: 20px;<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118><span class="line-number" data-v-558b0118>7</span><br data-v-558b0118><span class="line-number" data-v-558b0118>8</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><p>2、父子元素margin重叠</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="background:#ddd;overflow:hidden;width:200px;"><div style="background:yellow;"><h6 style="height:20px;background:pink;margin-top:40px;">我是marin-top: 40px;我的爸爸颜色是黄色</h6></div></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>overflow</span><span class="token punctuation" data-v-558b0118>:</span> hidden<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 200px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span>yellow<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
      <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>h6</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> pink<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>margin-top</span><span class="token punctuation" data-v-558b0118>:</span> 40px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是marin-top: 40px;我的爸爸颜色是黄色<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>h6</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118><span class="line-number" data-v-558b0118>7</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><p>解决方案: 给父元素转为BFC</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="background:#ddd;overflow:hidden;width:200px;"><div style="background:yellow;overflow:hidden;"><h6 style="height:20px;background:pink;margin-top:40px;">我是marin-top: 40px;我的爸爸颜色是黄色</h6></div></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>overflow</span><span class="token punctuation" data-v-558b0118>:</span> hidden<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 200px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span>yellow<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>overflow</span><span class="token punctuation" data-v-558b0118>:</span> hidden<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
      <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>h6</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> pink<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>margin-top</span><span class="token punctuation" data-v-558b0118>:</span> 40px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是marin-top: 40px;我的爸爸颜色是黄色<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>h6</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118><span class="line-number" data-v-558b0118>7</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><p>3、清除浮动（另一种方法：伪元素clear：both;清除浮动）</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div><div style="background:#ddd;overflow:hidden;width:200px;"><p style="width:50px;height:20px;border:1px;float:left;">浮动1：我的爸爸没设置高度，只设置了BFC</p> <p style="width:50px;height:20px;border:1px;float:left;">浮动2</p></div> <div>我是下一个元素</div></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>overflow</span><span class="token punctuation" data-v-558b0118>:</span> hidden<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 200px<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
      <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 50px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>border</span><span class="token punctuation" data-v-558b0118>:</span> 1px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>浮动1：我的爸爸没设置高度，只设置了BFC<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
      <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 50px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 20px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>border</span><span class="token punctuation" data-v-558b0118>:</span> 1px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>浮动2<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是下一个元素<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118><span class="line-number" data-v-558b0118>7</span><br data-v-558b0118><span class="line-number" data-v-558b0118>8</span><br data-v-558b0118><span class="line-number" data-v-558b0118>9</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><h2 id="css实现省略号"><a href="#css实现省略号" class="header-anchor">#</a> css实现省略号</h2> <h3 id="单行省略号"><a href="#单行省略号" class="header-anchor">#</a> 单行省略号</h3> <div class="language- line-numbers-mode"><pre class="language-text"><code>overflow: hidden;
text-overflow:ellipsis; // 显示省略号来代表被修剪的文本
white-space: nowrap; // 规定不换行
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="实现多行省略"><a href="#实现多行省略" class="header-anchor">#</a> 实现多行省略</h3> <p>因使用了WebKit的CSS扩展属性，该方法适用于WebKit浏览器及移动端；</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>display: -webkit-box;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="字母自动换行"><a href="#字母自动换行" class="header-anchor">#</a> 字母自动换行</h3> <div class="language- line-numbers-mode"><pre class="language-text"><code>word-break: normal|break-all|keep-all;
// break-all: 允许在单词内换行。keep-all: 只能在半角空格或连字符处换行。

word-wrap: normal|break-word;
// break-word: 在长单词或 URL 地址内部进行换行。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h2 id="伪类和伪元素"><a href="#伪类和伪元素" class="header-anchor">#</a> 伪类和伪元素</h2> <h3 id="伪类"><a href="#伪类" class="header-anchor">#</a> 伪类</h3> <p>:focus, :hover, :actived, :visted, :first-child, :last-child, :first-of-type, :last-of-type, :nth-child(n), :nth-child(odd), :nth-child(even)等</p> <h3 id="易错题"><a href="#易错题" class="header-anchor">#</a> 易错题</h3> <div class="language- line-numbers-mode"><pre class="language-text"><code>&lt;div&gt;
  &lt;span&gt;我是span:first-child&lt;/span&gt;
  &lt;p&gt;我不是p:first-child&lt;/p&gt;
  &lt;p&gt;我是p:nth-child(3)&lt;/p&gt;
  &lt;p&gt;我不是p:last-child&lt;/p&gt;
  &lt;span&gt;我是span:last-child&lt;/span&gt;
&lt;/div&gt;
// p:first-child表示div的第一个元素是p标签，而不是div的第一个p标签
// p:first-of-type, p:last-of-type表示div的第一个p标签和最后一个p标签
所以上次p:first-child, p:last-child都不生效。要改成p:first-of-type, p:last-of-type
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="伪元素"><a href="#伪元素" class="header-anchor">#</a> 伪元素</h3> <p>::after, ::before, ::first-letter, ::first-line, ::selection, ::backdrop</p> <h2 id="页面布局"><a href="#页面布局" class="header-anchor">#</a> 页面布局</h2> <h3 id="两列布局-后台管理"><a href="#两列布局-后台管理" class="header-anchor">#</a> 两列布局-后台管理</h3> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="width:300px;height:100px;background:#ddd;"><div style="width:50px;height:100%;float:left;background:yellow;">我是菜单</div> <div style="overflow-y:scroll;width:200px;height:100%;background:pink;">我是内容,我没有设置margin-left</div></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 300px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 50px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 100%<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> yellow<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是菜单<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>overflow-y</span><span class="token punctuation" data-v-558b0118>:</span> scroll<span class="token punctuation" data-v-558b0118>;</span><span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 200px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 100%<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> pink<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是内容,我没有设置margin-left<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><h3 id="圣杯布局"><a href="#圣杯布局" class="header-anchor">#</a> 圣杯布局</h3> <ol><li>给父元素设置左右padding, 位置预留给left，right。这样center可以设置100%，center放最前面，先渲染。三块都设置浮动。</li> <li>此时left，right会跳到center的下一行。所以left设置margin-left: 100%; right设置margin-left: -50px; 让left，right回到同一行。</li> <li>此时left, right因为padding的关系不是在最左右，所以设置position: relative; 设置left, right将两块移到最左右。</li></ol> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><article class="container"><div class="center"><h2>圣杯布局</h2></div> <div class="left"></div> <div class="right"></div></article></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>article</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>container<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>center<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
      <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>h2</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>圣杯布局<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>h2</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>left<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>right<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>article</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>style</span><span class="token punctuation" data-v-558b0118>&gt;</span></span><span class="token style" data-v-558b0118><span class="token language-css" data-v-558b0118>
  <span class="token selector" data-v-558b0118>.container</span><span class="token punctuation" data-v-558b0118>{</span>
    <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 500px<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 300px<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>padding-left</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>padding-right</span><span class="token punctuation" data-v-558b0118>:</span> 80px<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
  <span class="token selector" data-v-558b0118>.center</span><span class="token punctuation" data-v-558b0118>{</span>
    <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100%<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 100%<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> yellow<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
  <span class="token selector" data-v-558b0118>.left</span><span class="token punctuation" data-v-558b0118>{</span>
    <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 100%<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> red<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>margin-left</span><span class="token punctuation" data-v-558b0118>:</span> -100%<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>position</span><span class="token punctuation" data-v-558b0118>:</span> relative<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>left</span><span class="token punctuation" data-v-558b0118>:</span> -100px<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
  <span class="token selector" data-v-558b0118>.right</span><span class="token punctuation" data-v-558b0118>{</span>
    <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 80px<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 100%<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> orange<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>margin-left</span><span class="token punctuation" data-v-558b0118>:</span> -80px<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>position</span><span class="token punctuation" data-v-558b0118>:</span> relative<span class="token punctuation" data-v-558b0118>;</span>
    <span class="token property" data-v-558b0118>right</span><span class="token punctuation" data-v-558b0118>:</span> -50px<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
</span></span><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>style</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118><span class="line-number" data-v-558b0118>7</span><br data-v-558b0118><span class="line-number" data-v-558b0118>8</span><br data-v-558b0118><span class="line-number" data-v-558b0118>9</span><br data-v-558b0118><span class="line-number" data-v-558b0118>10</span><br data-v-558b0118><span class="line-number" data-v-558b0118>11</span><br data-v-558b0118><span class="line-number" data-v-558b0118>12</span><br data-v-558b0118><span class="line-number" data-v-558b0118>13</span><br data-v-558b0118><span class="line-number" data-v-558b0118>14</span><br data-v-558b0118><span class="line-number" data-v-558b0118>15</span><br data-v-558b0118><span class="line-number" data-v-558b0118>16</span><br data-v-558b0118><span class="line-number" data-v-558b0118>17</span><br data-v-558b0118><span class="line-number" data-v-558b0118>18</span><br data-v-558b0118><span class="line-number" data-v-558b0118>19</span><br data-v-558b0118><span class="line-number" data-v-558b0118>20</span><br data-v-558b0118><span class="line-number" data-v-558b0118>21</span><br data-v-558b0118><span class="line-number" data-v-558b0118>22</span><br data-v-558b0118><span class="line-number" data-v-558b0118>23</span><br data-v-558b0118><span class="line-number" data-v-558b0118>24</span><br data-v-558b0118><span class="line-number" data-v-558b0118>25</span><br data-v-558b0118><span class="line-number" data-v-558b0118>26</span><br data-v-558b0118><span class="line-number" data-v-558b0118>27</span><br data-v-558b0118><span class="line-number" data-v-558b0118>28</span><br data-v-558b0118><span class="line-number" data-v-558b0118>29</span><br data-v-558b0118><span class="line-number" data-v-558b0118>30</span><br data-v-558b0118><span class="line-number" data-v-558b0118>31</span><br data-v-558b0118><span class="line-number" data-v-558b0118>32</span><br data-v-558b0118><span class="line-number" data-v-558b0118>33</span><br data-v-558b0118><span class="line-number" data-v-558b0118>34</span><br data-v-558b0118><span class="line-number" data-v-558b0118>35</span><br data-v-558b0118><span class="line-number" data-v-558b0118>36</span><br data-v-558b0118><span class="line-number" data-v-558b0118>37</span><br data-v-558b0118><span class="line-number" data-v-558b0118>38</span><br data-v-558b0118><span class="line-number" data-v-558b0118>39</span><br data-v-558b0118><span class="line-number" data-v-558b0118>40</span><br data-v-558b0118><span class="line-number" data-v-558b0118>41</span><br data-v-558b0118><span class="line-number" data-v-558b0118>42</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><h3 id="双飞翼布局"><a href="#双飞翼布局" class="header-anchor">#</a> 双飞翼布局</h3> <p>和圣杯布局差不多，就是父元素不用padding，center用margin，更实用</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><article class="container"><div class="center"><div class="inner">双飞翼布局</div></div> <div class="left"></div> <div class="right"></div></article></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>article</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>container<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>center<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
        <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>inner<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>双飞翼布局<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>left<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token attr-name" data-v-558b0118>class</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span>right<span class="token punctuation" data-v-558b0118>&quot;</span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>article</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>style</span><span class="token punctuation" data-v-558b0118>&gt;</span></span><span class="token style" data-v-558b0118><span class="token language-css" data-v-558b0118>
  <span class="token selector" data-v-558b0118>.container</span> <span class="token punctuation" data-v-558b0118>{</span>
    <span class="token property" data-v-558b0118>min-width</span><span class="token punctuation" data-v-558b0118>:</span> 600px<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
  <span class="token selector" data-v-558b0118>.left</span> <span class="token punctuation" data-v-558b0118>{</span>
      <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 50px<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 300px<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> red<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>margin-left</span><span class="token punctuation" data-v-558b0118>:</span> -100%<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
  <span class="token selector" data-v-558b0118>.center</span> <span class="token punctuation" data-v-558b0118>{</span>
      <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100%<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 300px<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> yellow<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
  <span class="token selector" data-v-558b0118>.center .inner</span> <span class="token punctuation" data-v-558b0118>{</span>
      <span class="token property" data-v-558b0118>margin</span><span class="token punctuation" data-v-558b0118>:</span> 0 100px 0 50px<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
  <span class="token selector" data-v-558b0118>.right</span> <span class="token punctuation" data-v-558b0118>{</span>
      <span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 300px<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> blue<span class="token punctuation" data-v-558b0118>;</span>
      <span class="token property" data-v-558b0118>margin-left</span><span class="token punctuation" data-v-558b0118>:</span> -100px<span class="token punctuation" data-v-558b0118>;</span>
  <span class="token punctuation" data-v-558b0118>}</span>
</span></span><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>style</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118><span class="line-number" data-v-558b0118>6</span><br data-v-558b0118><span class="line-number" data-v-558b0118>7</span><br data-v-558b0118><span class="line-number" data-v-558b0118>8</span><br data-v-558b0118><span class="line-number" data-v-558b0118>9</span><br data-v-558b0118><span class="line-number" data-v-558b0118>10</span><br data-v-558b0118><span class="line-number" data-v-558b0118>11</span><br data-v-558b0118><span class="line-number" data-v-558b0118>12</span><br data-v-558b0118><span class="line-number" data-v-558b0118>13</span><br data-v-558b0118><span class="line-number" data-v-558b0118>14</span><br data-v-558b0118><span class="line-number" data-v-558b0118>15</span><br data-v-558b0118><span class="line-number" data-v-558b0118>16</span><br data-v-558b0118><span class="line-number" data-v-558b0118>17</span><br data-v-558b0118><span class="line-number" data-v-558b0118>18</span><br data-v-558b0118><span class="line-number" data-v-558b0118>19</span><br data-v-558b0118><span class="line-number" data-v-558b0118>20</span><br data-v-558b0118><span class="line-number" data-v-558b0118>21</span><br data-v-558b0118><span class="line-number" data-v-558b0118>22</span><br data-v-558b0118><span class="line-number" data-v-558b0118>23</span><br data-v-558b0118><span class="line-number" data-v-558b0118>24</span><br data-v-558b0118><span class="line-number" data-v-558b0118>25</span><br data-v-558b0118><span class="line-number" data-v-558b0118>26</span><br data-v-558b0118><span class="line-number" data-v-558b0118>27</span><br data-v-558b0118><span class="line-number" data-v-558b0118>28</span><br data-v-558b0118><span class="line-number" data-v-558b0118>29</span><br data-v-558b0118><span class="line-number" data-v-558b0118>30</span><br data-v-558b0118><span class="line-number" data-v-558b0118>31</span><br data-v-558b0118><span class="line-number" data-v-558b0118>32</span><br data-v-558b0118><span class="line-number" data-v-558b0118>33</span><br data-v-558b0118><span class="line-number" data-v-558b0118>34</span><br data-v-558b0118><span class="line-number" data-v-558b0118>35</span><br data-v-558b0118><span class="line-number" data-v-558b0118>36</span><br data-v-558b0118><span class="line-number" data-v-558b0118>37</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><h2 id="元素水平、垂直居中"><a href="#元素水平、垂直居中" class="header-anchor">#</a> 元素水平、垂直居中</h2> <h3 id="元素水平居中"><a href="#元素水平居中" class="header-anchor">#</a> 元素水平居中</h3> <p>行内元素</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="text-align:center;width:100px;height:50px;background:#ddd;"><p style="display:inline-flex;">我是居中</p></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>text-align</span><span class="token punctuation" data-v-558b0118>:</span> center<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 50px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
    <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> inline <span class="token punctuation" data-v-558b0118>;</span><span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> inline-block<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> inline-table<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> inline-flex<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>我是居中<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><p>块级元素</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>// 1、margin
.child{
  width: 100px;//确保该块级元素定宽
  margin:0 auto;
}

// 2、table+margin
.child {
  display: table; // 这样元素的宽就是内容的宽
  margin: 0 auto;
}

// 3、absolute+transform
.child {
  position:absolute;
  left:50%;
  transform:translateX(-50%);
}
.parent {
  position:relative;
}

// 4、flex
.parent {
  display: flex;
  justify-content:center;
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><h3 id="脱离文档流元素水平居中"><a href="#脱离文档流元素水平居中" class="header-anchor">#</a> 脱离文档流元素水平居中</h3> <p>浮动元素</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="display:flex;justify-content:center;width:100px;height:50px;background:#ddd;"><p style="float:left;background:yellow;">child</p></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> flex<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>justify-content</span><span class="token punctuation" data-v-558b0118>:</span> center<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 50px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>float</span><span class="token punctuation" data-v-558b0118>:</span> left<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> yellow<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>child<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><p>绝对定位元素 margin: 0 auto; left: 0; right: 0;</p> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="position:relative;width:500px;height:100px;background:#ddd;"><p style="position:absolute;margin:0 auto;left:0;right:0;width:100px;height:50px;background:yellow;">child</p></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>position</span><span class="token punctuation" data-v-558b0118>:</span> relative<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 500px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> #ddd<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>position</span><span class="token punctuation" data-v-558b0118>:</span> absolute<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>margin</span><span class="token punctuation" data-v-558b0118>:</span> 0 auto<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>left</span><span class="token punctuation" data-v-558b0118>:</span> 0<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>right</span><span class="token punctuation" data-v-558b0118>:</span> 0<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 50px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>background</span><span class="token punctuation" data-v-558b0118>:</span> yellow<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>child<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><h3 id="垂直居中"><a href="#垂直居中" class="header-anchor">#</a> 垂直居中</h3> <ol><li>line-height + height</li> <li>flex + align-items</li> <li>table</li></ol> <div class="demo-block demo-zh-CN demo-css.html" data-v-558b0118><div class="demo-content" data-v-558b0118><div><div style="display:table;width:100px;height:140px;border:2px dashed #f69c55;"><p style="display:table-cell;vertical-align:middle;">child</p></div></div></div> <div class="meta" data-v-558b0118><!----> <div class="code-content" data-v-558b0118><div class="language-html line-numbers-mode" data-v-558b0118><pre class="language-html" data-v-558b0118><code data-v-558b0118><span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>div</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> table<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>width</span><span class="token punctuation" data-v-558b0118>:</span> 100px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>height</span><span class="token punctuation" data-v-558b0118>:</span> 140px<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>border</span><span class="token punctuation" data-v-558b0118>:</span> 2px dashed #f69c55<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
  <span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;</span>p</span> <span class="token special-attr" data-v-558b0118><span class="token attr-name" data-v-558b0118>style</span><span class="token attr-value" data-v-558b0118><span class="token punctuation attr-equals" data-v-558b0118>=</span><span class="token punctuation" data-v-558b0118>&quot;</span><span class="token value css language-css" data-v-558b0118><span class="token property" data-v-558b0118>display</span><span class="token punctuation" data-v-558b0118>:</span> table-cell<span class="token punctuation" data-v-558b0118>;</span> <span class="token property" data-v-558b0118>vertical-align</span><span class="token punctuation" data-v-558b0118>:</span> middle<span class="token punctuation" data-v-558b0118>;</span></span><span class="token punctuation" data-v-558b0118>&quot;</span></span></span><span class="token punctuation" data-v-558b0118>&gt;</span></span>child<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>p</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>div</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
<span class="token tag" data-v-558b0118><span class="token tag" data-v-558b0118><span class="token punctuation" data-v-558b0118>&lt;/</span>template</span><span class="token punctuation" data-v-558b0118>&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper" data-v-558b0118><span class="line-number" data-v-558b0118>1</span><br data-v-558b0118><span class="line-number" data-v-558b0118>2</span><br data-v-558b0118><span class="line-number" data-v-558b0118>3</span><br data-v-558b0118><span class="line-number" data-v-558b0118>4</span><br data-v-558b0118><span class="line-number" data-v-558b0118>5</span><br data-v-558b0118></div></div></div></div> <div class="demo-block-control" style="width:unset;" data-v-558b0118><i class="caret-bottom icon" data-v-558b0118 data-v-558b0118></i> <span style="display:none;" data-v-558b0118 data-v-558b0118>显示代码</span> <span class="copy-action" style="display:;" data-v-558b0118>复制代码</span> <span class="copy-action copy-action-success" style="display:none;" data-v-558b0118 data-v-558b0118>复制代码</span></div></div><h3 id="水平垂直居中"><a href="#水平垂直居中" class="header-anchor">#</a> 水平垂直居中</h3> <div class="language- line-numbers-mode"><pre class="language-text"><code>// margin+absolute
#container {
  position: relative;
  height:100px;//必须有个高度
}
#center {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;//注意此处的写法
}

// absolute + transform
#container {
  position: relative;
}
#center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// flex布局
#container { //直接在父容器设置即可
  height: 100vh; //必须有高度
  display: flex;
  justify-content: center;
  align-items: center;
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2022/7/8 上午10:51:20</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/vue-admin-ui/assets/js/app.21d1badc.js" defer></script><script src="/vue-admin-ui/assets/js/3.d02ddc64.js" defer></script><script src="/vue-admin-ui/assets/js/1.38c8ef5a.js" defer></script><script src="/vue-admin-ui/assets/js/11.284df538.js" defer></script>
  </body>
</html>
